import { IPoint } from "../js/interface";
export namespace UL {
  export function getMousePos(
    domElement: Element,
    e: any | IPoint,
    cbOut = true
  ): IPoint & { isoutX?: boolean; isoutY?: boolean } {
    let mouseX: number = 0;
    let mouseY: number = 0;

    if (e.clientX && e.clientY) {
      mouseX = e.clientX;
      mouseY = e.clientY;
    } else if (e.touches && e.touches.length > 0) {
      if (e.touches[0]) {
        mouseX = e.touches[0].clientX;
        mouseY = e.touches[0].clientY;
      } else if (e.changedTouches) {
        mouseX = e.changedTouches[0].clientX;
        mouseY = e.changedTouches[0].clientY;
      }
    }

    let { left, top, width, height } = domElement.getBoundingClientRect();

    let x = mouseX - left;
    let y = mouseY - top;
    let isoutX = false;
    let isoutY = false;

    if (x >= width) {
      isoutX = true;
    }
    if (x <= 0) {
      isoutX = true;
    }
    if (y >= height) {
      isoutY = true;
    }
    if (y <= 0) {
      isoutY = true;
    }

    return { x, y, isoutX, isoutY };
  }
}
